/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.oraclefmw.weibo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import weibo4j.User;
import weibo4j.WeiboException;
import static java.lang.System.out;

/**
 *
 * @author gniu
 */
public class Yekki extends WeiboGeneric{

    private List<User> friends;
    private List<User> followers;
    private static Yekki yekki;
    
    private Yekki() {
        
    }
    private void initialize() throws WeiboException {
        
        friends = getUsers(WeiboGeneric.FRIEND);
        followers = getUsers(WeiboGeneric.FOLLOWER);
    }
    
    private void printHeader( String msg ) {
    
        out.println( "***** " + msg + "*****" );
    }
    
    public void listFaithlessFriends() throws WeiboException {
        
        printHeader( "Faithless Friends ");
        
        Collection<User> secUsers = CollectionUtils.intersection(friends, followers);
        Collection<User> subUsers = CollectionUtils.subtract(friends, secUsers);

        for (User u : subUsers) {
            System.out.println(u.getScreenName());
        }
        
        out.println( "Grand Total:" + subUsers.size() );

    }

    public void listActiveFollowers() throws WeiboException {
        
        printHeader( "Active Followers");
        
        List<User> tempUsers = new ArrayList<User>();
        
        for ( User u:followers) {
            
            if ( u.getStatusesCount() > 3000 ) {
                tempUsers.add( u );
            }
        }
        
        Collection<User> secUsers = CollectionUtils.intersection(friends, tempUsers);
        Collection<User> subUsers = CollectionUtils.subtract(tempUsers, secUsers);
        
         for (User u : subUsers) {
            System.out.println(u.getScreenName());
        }
        
        out.println( "Grand Total:" + subUsers.size() );
    }
    
    public void listVerifiedFollowers() throws WeiboException {
        
        printHeader( "Verified Followers");
        
        List<User> vUsers = new ArrayList<User>();
        
        for ( User u:followers ) {
            
            if ( u.isVerified() ) {
                
                vUsers.add( u );
                
                System.out.println( u.getScreenName() );
            }
        }
        
        out.println( "Grand Total:" + vUsers.size() );
    }
    
    public void calculateFollowerCount() throws WeiboException {
        
        printHeader( "Influence Funs Count");
        
        int count = 0;
        
        for ( User u:followers ) {
 
            count += u.getFollowersCount();
        }
        
        out.println( "Grand Total:" + count );
    }
    
    public void listInfluentialFollowers() throws WeiboException {
        
        printHeader( "Influential Followers");
        
        List<User> tempUsers = new ArrayList<User>();
        
        for ( User u:followers) {
            
            if ( u.getFollowersCount() > 1000 ) {
                tempUsers.add( u );
            }
        }
        
        Collection<User> secUsers = CollectionUtils.intersection(friends, tempUsers);
        Collection<User> subUsers = CollectionUtils.subtract(tempUsers, secUsers);
        
         for (User u : subUsers) {
         
            System.out.println(u.getScreenName());
        }
        
        out.println( "Grand Total:" + subUsers.size() );
    }
    
     public void listUninfluentialNotVerifiedFriends() throws WeiboException {
        
        printHeader( "Uninfluential Not Verified Friends");
        
        List<User> tempUsers = new ArrayList<User>();
        
        for ( User u:friends) {
            
            if ( ( u.getFollowersCount() < 1000 ) && ( !u.isVerified()) ) {
                tempUsers.add( u );
            }
        }
        
        
        for (User u : tempUsers) {
           
            System.out.println(u.getScreenName());
        }
        
        out.println( "Grand Total:" + tempUsers.size() );
    }
     
      public void listUninfluentialVerifiedFriends() throws WeiboException {
        
        printHeader( "Uninfluential Verified Friends");
        
        List<User> tempUsers = new ArrayList<User>();
        
        for ( User u:friends) {
            
            if ( ( u.getFollowersCount() < 350 ) && ( u.isVerified()) ) {
                tempUsers.add( u );
            }
        }
        
        
        for (User u : tempUsers) {
           
            System.out.println(u.getScreenName());
        }
        
        out.println( "Grand Total:" + tempUsers.size() );
    }
    
    public static Yekki getInstance() throws WeiboException {
    
        if ( yekki == null ) {
            yekki = new Yekki();
            yekki.initialize();
        }
        
        return yekki;
    }
    
    public void persist() throws Exception {
        
       // persistUsers( friends, false );
        //persistUsers( followers, true );
    }
    
    public static void main(String[] args) throws Exception {
        
        Yekki main = Yekki.getInstance();
        main.listFaithlessFriends();
       // main.listUninfluentialNotVerifiedFriends();
       // main.persist();
        //main.listUninfluentialVerifiedFriends();
       // main.listVerifiedFollowers();
        //main.listActiveFollowers();
       // main.listInfluentialFollowers();
        //main.listFaithlessFriends();
       // main.listVerifiedFollowers();;
    }
}
